/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Component;

import Global.ResourceManager;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;

/**
 *
 * @author Huy
 */
public class MyTextButton extends MyButton {

	private String text;

	public MyTextButton(BufferedImage img, String text, int x, int y) {
		super(img, x, y);
		this.text = text;
	}
	public MyTextButton(String text, int x, int y) {
		super(ResourceManager.getImage("default/button"), x, y);
		this.text = text;
	}

		
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	@Override
	public void draw(Graphics2D g) {
		if (!isVisible) {
			return;
		}
		sprite.draw(g);
		
		if (isEnable) {
			g.setColor(foreColor);
		} else {
			g.setColor(disableColor);
		}
		
		Rectangle2D textBound = g.getFont().getStringBounds(text, g.getFontRenderContext());
		Rectangle spriteBound = sprite.getBound();
		int x = (int) (spriteBound.getCenterX() - textBound.getCenterX());
		int y = (int) (spriteBound.getCenterY() - textBound.getCenterY());
		g.drawString(text, x, y);

	}
}
